<template>
	<view class="uni-steps">
		<view :class="[direction === 'column' ? 'uni-steps__column' : 'uni-steps__row']">
			<view :class="[direction === 'column' ? 'uni-steps__column-text-container2' : 'uni-steps__row-text-container']">
				<view v-for="(item, index) in options" :key="index" :class="[direction === 'column' ? 'uni-steps__column-text' : 'uni-steps__row-text']">
					<text :style="{ color: index <= active ? activeColor : deactiveColor }" :class="[direction === 'column' ? 'uni-steps__column-desc' : 'uni-steps__row-desc']">
						<text v-if="item.id === active" style="color: #CD001B">{{ item.title }}</text>
						<text v-else>{{ item.title }}</text>
					</text>
					<!-- 		<text :style="{ color: item.id === active ? activeColor : deactiveColor }" :class="[direction === 'column' ? 'uni-steps__column-desc' : 'uni-steps__row-desc']">
						{{ arr[index] }}
					</text> -->
					<text class="thailandWarehouseBox" v-if="thailandWarehouseComputed(index)">{{ thailandWarehouse }}</text>
				</view>
			</view>

			<view :class="[direction === 'column' ? 'uni-steps__column-container' : 'uni-steps__row-container']">
				<view :class="[direction === 'column' ? 'uni-steps__column-line-item' : 'uni-steps__row-line-item']" v-for="(item, index) in options" :key="index">
					<view :class="[direction === 'column' ? 'uni-steps__column-check' : 'uni-steps__row-check', index == active ? 'data-scroll' : '']">
						<!-- index <= active && active !== '' ? '#CD001B' : '#AEB0B3' -->
						<uni-icons :color="iconColor(index, active)" type="checkbox-filled" :size="direction === 'column' ? 20 : 30"></uni-icons>
					</view>
					<view
						:style="{ backgroundColor: index <= active && active !== '' ? '#F77687' : '#aeb0b3' }"
						:class="direction === 'column' ? 'uni-steps__column-line' : 'uni-steps__row-line'"
						v-show="index !== options.length - 1 ? true : false"
					></view>
					<!-- <dotted-line v-if="direction === 'column'" :dash="false" Y dash-width="10" v-show="index !== options.length - 1 ? true : false" style=""></dotted-line> -->
				</view>
			</view>
			<view :class="[direction === 'column' ? 'uni-steps__column-text-container' : 'uni-steps__row-text-container']">
				<view v-for="(item, index) in options" :key="index" :class="[direction === 'column' ? 'uni-steps__column-text' : 'uni-steps__row-text']">
					<text :style="{ color: index <= active ? activeColor : deactiveColor }" :class="[direction === 'column' ? 'uni-steps__column-title2' : 'uni-steps__row-title']">
						<!-- {{ item.title }} -->
						<text v-if="item.id === active" style="color: #CD001B">{{ arr[index] }}</text>
						<text v-else>{{ arr[index] }}</text>
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import dottedLine from '@/pages/logins/dottedLine.vue';
/**
 * Steps 步骤条
 * @description 评分组件
 * @tutorial https://ext.dcloud.net.cn/plugin?id=34
 * @property {Number} active 当前步骤
 * @property {String} direction = [row|column] 当前步骤
 * 	@value row 横向
 * 	@value column 纵向
 * @property {String} activeColor 选中状态的颜色
 * @property {Array} options 数据源，格式为：[{title:'xxx',desc:'xxx'},{title:'xxx',desc:'xxx'}]
 */

export default {
	name: 'stepsBox',
	props: {
		direction: {
			// 排列方向 row column
			type: String,
			default: 'row'
		},
		activeColor: {
			// 激活状态颜色
			type: String,
			default: '#F77687'
		},
		deactiveColor: {
			// 未激活状态颜色
			type: String,
			default: '#999999'
		},
		active: {
			// 当前步骤
			type: [Number, String],
			default: ''
		},
		thailandWarehouse: {
			// 泰国仓库名称
			type: String,
			default: ''
		},
		options: {
			type: Array,
			default() {
				return [];
			}
		} // 数据
	},
	components: { dottedLine },
	computed: {
		i18n() {
			return this.$t('orderTracking');
		},
		arr() {
			if (this.options.length === 6) {
				return [
					this.$t('orderTracking').ctwfont19,
					this.$t('orderTracking').ctwfont18,
					this.$t('orderTracking').ctwfont17,
					this.$t('orderTracking').ctwfont27,
					// this.$t('orderTracking').ctwfont15,
					this.$t('orderTracking').ctwfont14,
					this.$t('orderTracking').ctwfont13
				];
			} else {
				return [
					this.$t('orderTracking').ctwfont19,
					this.$t('orderTracking').ctwfont18,
					this.$t('orderTracking').ctwfont17,
					this.$t('orderTracking').ctwfont16,
					this.$t('orderTracking').ctwfont15,
					this.$t('orderTracking').ctwfont14,
					this.$t('orderTracking').ctwfont13
				];
			}
		},
		thailandWarehouseComputed() {
			return function(val) {
				if (this.options.length === 6) {
					if (val === 4) {
						return true;
					} else {
						return false;
					}
				} else {
					if (val === 5) {
						return true;
					} else {
						return false;
					}
				}
			};
		},
		iconColor() {
			return function(index, active) {
				if (active !== '') {
					if (index < active) {
						return '#F77687';
					} else if (index == active) {
						return '#CD001B';
					} else {
						return '#AEB0B3';
					}
				} else {
					return '#AEB0B3';
				}
			};
		}
	},
	mounted() {
		// 页面加载完成返回状态位置
		this.$nextTick(function() {
			this.monthDistance();
		});
	},
	methods: {
		monthDistance() {
			let _this = this;
			uni.createSelectorQuery()
				.in(_this)
				.selectAll('.data-scroll')
				.boundingClientRect(function(res) {
					res.forEach(item => {
						_this.$emit('leftScroll', item.left - 750/4);
					});
				})
				.exec();
		}
	}
};
</script>

<style scoped>
.thailandWarehouseBox {
	position: absolute;
	left: 0;
	top: 35%;
	font-size: $uni-font-size-custom-b;
	line-height: 12px;
	color: #999999;
	word-break: break-all; // 强制换行
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; //多行在这里修改数字即可
	overflow: hidden;
	-webkit-box-orient: vertical;
}
.uni-steps {
	/* #ifndef APP-NVUE */
	display: flex;
	width: 100%;
	/* #endif */
	/* #ifdef APP-NVUE */
	flex: 1;
	/* #endif */
	flex-direction: column;
}

.uni-steps__row {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
}

.uni-steps__column {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: row-reverse;
}

.uni-steps__row-text-container {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: row;
}

.uni-steps__column-text-container {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	flex: 1;
	/* margin-bottom: 20px; */
}
.uni-steps__column-text-container2 {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	flex: 1.5;
	/* margin-bottom: 20px; */
}

.uni-steps__row-text {
	position: relative;
	left: 12px;
	transform: translateX(-50%);
	/* #ifndef APP-NVUE */
	display: inline-flex;
	/* #endif */
	flex: 1;
	flex-direction: column;
	width: 80px;
}

.uni-steps__column-text {
	position: relative;
	/* padding: 6px 0px; */
	/* 	border-bottom-style: solid;
	border-bottom-width: 1px;
	border-bottom-color: #e5e5e5; */
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
}

.uni-steps__row-title {
	padding-top: 5px;
	font-size: $uni-font-size-custom-b;
	line-height: 16px;
	text-align: center;

	word-break: break-all; // 强制换行
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; //多行在这里修改数字即可
	overflow: hidden;
	-webkit-box-orient: vertical;
}

.uni-steps__column-title {
	font-size: $uni-font-size-custom-b;
	text-align: left;
	line-height: 18px;
	word-break: break-all; // 强制换行
}
.uni-steps__column-title2 {
	font-size: $uni-font-size-custom-b;
	text-align: right;
	line-height: 14px;
	/* margin-right: 20px; */
	text-align: center;
	height: 40px;
	/* margin-bottom: 30px; */
	word-break: break-all; // 强制换行
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; //多行在这里修改数字即可
	overflow: hidden;
	-webkit-box-orient: vertical;
}

.uni-steps__row-desc {
	font-size: $uni-font-size-custom-b;
	line-height: $uni-font-size-custom-d;
	text-align: center;
	word-break: break-all; // 强制换行
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; //多行在这里修改数字即可
	overflow: hidden;
	-webkit-box-orient: vertical;
	/* padding-bottom: 10px; */
}

.uni-steps__column-desc {
	font-size: $uni-font-size-custom-b;
	text-align: left;
	line-height: 14px;
	/* margin-left: 20px; */
	/* text-align: center; */
	height: 40px;
	/* margin-bottom: 30px; */
	word-break: break-all; // 强制换行
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; //多行在这里修改数字即可
	overflow: hidden;
	-webkit-box-orient: vertical;
}

.uni-steps__row-container {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: row;
}

.uni-steps__column-container {
	/* margin-top: 8px; */
	/* #ifndef APP-NVUE */
	display: inline-flex;
	/* #endif */
	width: 30px;
	flex-direction: column;
}

.uni-steps__row-line-item {
	/* #ifndef APP-NVUE */
	display: inline-flex;
	/* #endif */
	flex-direction: row;
	flex: 1;
	align-items: center;
	/* justify-content: center; */
}

.uni-steps__column-line-item {
	/* 	margin-top: 8px; */
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	flex: 1;
	align-items: center;
	/* justify-content: center; */
}

.uni-steps__row-line {
	flex: 1;
	height: 4px;
	background-color: #aeb0b3;
}

.uni-steps__column-line {
	width: 2px;
	background-color: #e4e4e4;
}

.uni-steps__row-circle {
	width: 5px;
	height: 5px;
	border-radius: 100px;
	background-color: #999;
	margin: 0px 3px;
}

.uni-steps__column-circle {
	width: 5px;
	height: 5px;
	border-radius: 100px;
	background-color: #999;
	margin: 4px 0px 5px 0px;
}

.uni-steps__row-check {
	/* margin: 0px 6px; */
}

.uni-steps__column-check {
	height: 14px;
	line-height: 14px;
	margin: 1px 0px;
}
</style>
